package com.twu.biblioteca;

public class Library {

    private LibraryShelf availableBookShelf;
    private LibraryShelf reservedBookShelf;
    private LibraryShelf availableMovieShelf;

    public Library() {
        availableBookShelf = new LibraryShelf();
        reservedBookShelf = new LibraryShelf();
        availableMovieShelf = new LibraryShelf();
    }

    public int size() {
        return availableBookShelf.size();
    }

    public Library addBook(Book book) {
        availableBookShelf.add(book);
        return this;
    }

    public Book get(int index) {
        return (Book) availableBookShelf.get(index);
    }


    public boolean bookIsReserved(Book book) {
        return reservedBookShelf.contains(book);
    }

    public Library reserveBook(Book book) {
        if (availableBookShelf.contains(book)) {
            reservedBookShelf.add(book);
            availableBookShelf.remove(book);
        }
        return this;
    }

    public Book getBookWithTitle(String title) {

        ShelfItem book = availableBookShelf.getItemWithTitle(title);
        if (book == null) {
            book = reservedBookShelf.getItemWithTitle(title);
        }

        return (Book) book;
    }

    public LibraryShelf getAvailableBookShelf() {
        return availableBookShelf;
    }

    public Library addMovie(Movie movie) {
        availableMovieShelf.add(movie);
        return this;
    }

    public boolean hasMovie(Movie movie) {
        return availableMovieShelf.contains(movie);
    }

    @Override
    public String toString() {
        return availableBookShelf.toString() + reservedBookShelf.toString();
    }

    public LibraryShelf getAvailableMovieShelf() {
        return availableMovieShelf;
    }
}
